﻿using System;
using System.Collections.Generic;
using System.Text;
using Nelibur.ObjectMapper;

namespace Best.SmartCms.Utility
{
    public static class TinyMapperExtensions
    {
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <typeparam name="TTarget"></typeparam>
        /// <param name="source"></param>
        /// <returns></returns>
        public static TTarget Map<TSource, TTarget>(TSource source)
        {
            if (!TinyMapper.BindingExists<TSource, TTarget>())
            {
                TinyMapper.Bind<TSource, TTarget>();
            }
            return TinyMapper.Map<TTarget>(source);
        }


        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <typeparam name="TTarget"></typeparam>
        /// <param name="source"></param>
        /// <returns></returns>
        public static TTarget Map<TSource, TTarget>(TSource source, TTarget target)
        {
            if (!TinyMapper.BindingExists<TSource, TTarget>())
            {
                TinyMapper.Bind<TSource, TTarget>();
            }
            return TinyMapper.Map(source, target);
        }
    }
}
